package com.ruicar.afs.cloud.basic.detail.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.ruicar.afs.cloud.basic.common.entity.*;
import com.ruicar.afs.cloud.basic.common.service.*;
import com.ruicar.afs.cloud.basic.creditchange.vo.ContractBasicListVO;
import com.ruicar.afs.cloud.basic.detail.vo.*;
import com.ruicar.afs.cloud.common.config.ContractFeginConfig;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumUtil;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import com.ruicar.afs.cloud.common.modules.contract.enums.*;
import com.ruicar.afs.cloud.common.util.EmptyUtils;
import com.ruicar.afs.cloud.manage.api.dto.OverpaymentDifferenceDTO;
import com.ruicar.afs.cloud.manage.api.feign.repayment.RepaymentDateChangeService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.*;

/**
 * @author: Lee
 * @date: 2020/5/11 19:39
 * @description: 合同明细信息查询
 */
@Slf4j
@RestController
@RequestMapping("/contractDetail")
@AllArgsConstructor
public class ContractDetailController {
    private final BasicMainInfoService basicMainInfoService;
    private final BasicReceiptRecordService basicReceiptRecordService;
    private final BasicAffiliatedUnitService basicAffiliatedUnitService;
    private final BasicCustBaseInfoService basicCustBaseInfoService;
    private final BasicFinancialAgreementService basicFinancialAgreementService;
    private final BasicCarDetailsService basicCarDetailsService;
    private final BasicProductParamService basicProductParamService;
    private final RepaymentDateChangeService repaymentDateChangeService;
    private final BasicRepaymentPlanService basicRepaymentPlanService;
    private final ContractFeginConfig contractFeginConfig;
    private final BasicChannelInfoService basicChannelInfoService;
    private final BasicCustPersonalDetailService basicCustPersonalDetailService;
    private final BasicContractCustRelationService basicContractCustRelationService;
    private final BasicCustContactsService basicCustContactsService;
    private final BasicCustAddressDetailsService basicCustAddressDetailsService;
    private final BasicCustContactDetailsService basicCustContactDetailsService;
    private final BasicPenaltyInterestService basicPenaltyInterestService;
    private final BasicExpenseRecordService basicExpenseRecordService;

    @ApiOperation(value = "多条件查询合同列表")
    @PostMapping("/list")
    public IResponse<IPage<List<ContractBasicListVO>>> ContractList(@RequestBody QueryListVO query) {
        Page page = new Page(query.getPageNumber(), query.getPageSize());
        IPage<List<QueryListVO>> voList = basicMainInfoService.queryContractInfo(page, query);
        return IResponse.success(voList);
    }

    @ApiOperation(value = "根据合同号码查询合同详细信息")
    @PostMapping("/detail")
    public IResponse<ContractDetailVO> contractDetail(@RequestParam("contractNo") String contractNo) {
        ContractDetailVO vo = new ContractDetailVO();

        //合同信息
        BasicMainInfo basicMainInfo = basicMainInfoService.getOne(Wrappers.<BasicMainInfo>lambdaQuery().eq(BasicMainInfo::getContractNo, contractNo));
        List<BasicAffiliatedUnit> basicAffiliatedUnits = basicAffiliatedUnitService.list(Wrappers.<BasicAffiliatedUnit>lambdaQuery().eq(BasicAffiliatedUnit::getContractNo, contractNo));
        ContractInfoVO contractInfo = new ContractInfoVO();
        if (EmptyUtils.isNotEmpty(basicMainInfo)) {
            BeanUtils.copyProperties(basicMainInfo, contractInfo);
            //业务合作伙伴信息
            ChannelInfoVO channelInfo = new ChannelInfoVO();
            channelInfo.setChannelName(basicMainInfo.getChannelFullName());
            channelInfo.setChannelType(basicMainInfo.getChannelType());
            vo.setChannelInfo(channelInfo);
        }
        if (EmptyUtils.isNotEmpty(basicAffiliatedUnits) && EmptyUtils.isNotEmpty(basicAffiliatedUnits.get(0).getAffiliatedType())) {
            contractInfo.setAffiliatedType(basicAffiliatedUnits.get(0).getAffiliatedType());
        }
        //客户信息
        List<CustInfoVO> custInfos = basicCustBaseInfoService.queryCustInfo(contractNo);

        //财务信息
        List<BasicFinancialAgreement> basicFinancialAgreements = basicFinancialAgreementService.list(Wrappers.<BasicFinancialAgreement>lambdaQuery().
                eq(BasicFinancialAgreement::getContractNo, contractNo));
        BasicProductParam basicProductParam = basicProductParamService.getOne(Wrappers.<BasicProductParam>lambdaQuery().
                eq(BasicProductParam::getContractNo, contractNo).eq(BasicProductParam::getAtomKey, AfsEnumUtil.key(ProductAtomEnum.RATE_TYPE)));

        //财务信息  CAR车辆信息
        List<FinanceInfoVO> financeInfos = new ArrayList<>();
        FinanceInfoVO financeInfoCar = new FinanceInfoVO();
        FinanceInfoVO financeInfoAdditional = new FinanceInfoVO();
        BigDecimal addAmt = BigDecimal.ZERO;
        if (EmptyUtils.isNotEmpty(basicFinancialAgreements)) {
            for (BasicFinancialAgreement agreement : basicFinancialAgreements) {
                //车款
                if (AssetTypeEnum.CAR_AMT == agreement.getCostType()) {
                    financeInfoCar.setProductName(basicMainInfo.getProductName());
                    financeInfoCar.setType(AssetTypeEnum.CAR_AMT);
                    financeInfoCar.setContractAmt(agreement.getContractAmt());
                    financeInfoCar.setIsLpr(EmptyUtils.isNotEmpty(basicProductParam) ? basicProductParam.getAtomValue() : null);
                    financeInfoCar.setDownPayAmt(agreement.getDownPayAmt());
                    financeInfoCar.setDownPayScale(agreement.getDownPayScale());
                    financeInfoCar.setLoanAmt(agreement.getLoanAmt());
                    financeInfoCar.setMonthPayAmt(agreement.getMonthPayAmt());
                    financeInfoCar.setCustRate(agreement.getCustRate());
                    financeInfoCar.setSettleRate(agreement.getSettleRate());
                    financeInfoCar.setDiscountRate(agreement.getSettleRate().subtract(agreement.getCustRate()));
                    financeInfoCar.setTailPayAmt(agreement.getTailPayAmt());
//                    financeInfoCar.setFinancPercent(new BigDecimal(100).subtract(agreement.getDownPayScale()));
                    financeInfoCar.setFinancPercent(agreement.getLoanAmt());
                } else {
                    //附加贷款
                    financeInfoAdditional.setProductName(basicMainInfo.getProductName());
                    financeInfoAdditional.setType(AssetTypeEnum.ADDITIONAL);
                    addAmt = agreement.getContractAmt() == null ? BigDecimal.ZERO : agreement.getContractAmt();
                    financeInfoAdditional.setContractAmt(agreement.getContractAmt());
                    financeInfoAdditional.setIsLpr(EmptyUtils.isNotEmpty(basicProductParam) ? basicProductParam.getAtomValue() : null);
                    financeInfoAdditional.setDownPayAmt(agreement.getDownPayAmt());
                    financeInfoAdditional.setDownPayScale(agreement.getDownPayScale());
                    financeInfoAdditional.setLoanAmt(agreement.getLoanAmt());
                    financeInfoAdditional.setMonthPayAmt(agreement.getMonthPayAmt());
                    financeInfoAdditional.setCustRate(agreement.getCustRate());
                    financeInfoAdditional.setSettleRate(agreement.getSettleRate());
                    financeInfoAdditional.setDiscountRate(agreement.getSettleRate().subtract(agreement.getCustRate()));
                    financeInfoAdditional.setTailPayAmt(agreement.getTailPayAmt());
//                    financeInfoAdditional.setFinancPercent(new BigDecimal(100).subtract(agreement.getDownPayScale()));
                    financeInfoAdditional.setFinancPercent(agreement.getLoanAmt());
                }
            }
            //财务信息  TOTAL汇总
            BasicFinancialAgreement agreement = new BasicFinancialAgreement();
            agreement = agreement.sum(basicFinancialAgreements);
            FinanceInfoVO financeInfoTotal = new FinanceInfoVO();
            BeanUtils.copyProperties(agreement, financeInfoTotal);
            financeInfoTotal.setProductName(basicMainInfo.getProductName());
            financeInfoTotal.setType(AssetTypeEnum.TOTAL);
            financeInfoTotal.setAddAmt(addAmt);
            financeInfoTotal.setIsLpr(EmptyUtils.isNotEmpty(basicProductParam) ? basicProductParam.getAtomValue() : null);
            Map<String, String> heards = new HashMap<>();
            heards.put(AfsEnumUtil.key(ContractFeginParamEnum.MANAGE_CLIENT_ID), contractFeginConfig.getManageClientId());
            heards.put(AfsEnumUtil.key(ContractFeginParamEnum.MANAGE_CLIENT_SECRET), contractFeginConfig.getManageClientSecret());
            IResponse<OverpaymentDifferenceDTO> response = repaymentDateChangeService.queryOverpaymentOrDifference(contractNo, heards);
            if ("0000".equals(response.getCode()) && EmptyUtils.isNotEmpty(response.getData())) {
                OverpaymentDifferenceDTO overpaymentDifference = response.getData();
                if (OverpaymentDifferenceTypeEnum.DIFFERENCE == overpaymentDifference.getType()) {
                    financeInfoTotal.setDifference(overpaymentDifference.getAmount());
                } else {
                    financeInfoTotal.setOverpayment(overpaymentDifference.getAmount());
                }
            }

            financeInfos.add(financeInfoCar);
            financeInfos.add(financeInfoAdditional);
            financeInfos.add(financeInfoTotal);
        }

        //租金明细信息
        List<RentInfoVO> rentInfoVOS = basicRepaymentPlanService.queryRepaymentInfo(contractNo,null);
        List<BasicExpenseRecord> basicExpenseRecords = basicExpenseRecordService.list(Wrappers.<BasicExpenseRecord>lambdaQuery().
                eq(BasicExpenseRecord::getContractNo, contractNo));
        RentInfoVO rentInfo = new RentInfoVO();

        if (EmptyUtils.isNotEmpty(rentInfoVOS)){
            rentInfo = rentInfoVOS.get(0);
            if (EmptyUtils.isNotEmpty(basicExpenseRecords)&&basicExpenseRecords.size()>0) {
                for (BasicExpenseRecord basicExpenseRecord : basicExpenseRecords) {
                    BigDecimal remainingAmt = basicExpenseRecord.getRemainingAmt();
                    rentInfo.setReceivableTotal(remainingAmt.add(rentInfo.getReceivableTotal()));
                }
            }
        }
        //资产信息
        List<BasicCarDetails> basicCarDetails = basicCarDetailsService.list(Wrappers.<BasicCarDetails>lambdaQuery().
                eq(BasicCarDetails::getContractNo, contractNo));
        if (EmptyUtils.isNotEmpty(basicCarDetails)) {
            AssetsInfoVO assetsInfo = JSON.parseObject(JSON.toJSONString(basicCarDetails.get(0)), AssetsInfoVO.class);
            vo.setAssetsInfo(EmptyUtils.isNotEmpty(assetsInfo) ? assetsInfo : new AssetsInfoVO());
        }

        //挂靠信息
        List<BasicAffiliatedUnit> affiliatedUnits = basicAffiliatedUnitService.list(Wrappers.<BasicAffiliatedUnit>lambdaQuery().
                eq(BasicAffiliatedUnit::getContractNo, contractNo));
        if (EmptyUtils.isNotEmpty(affiliatedUnits)) {
            AffiliatedInfoVO affiliatedInfo = JSON.parseObject(JSON.toJSONString(affiliatedUnits.get(0)), AffiliatedInfoVO.class);
            vo.setAffiliatedInfo(EmptyUtils.isNotEmpty(affiliatedInfo) ? affiliatedInfo : new AffiliatedInfoVO());
        }
        vo.setContractInfo(contractInfo);
        vo.setCustInfo(EmptyUtils.isNotEmpty(custInfos) ? custInfos : Lists.newArrayList());
        vo.setFinanceInfo(financeInfos);
        vo.setRentInfo(EmptyUtils.isNotEmpty(rentInfo) ? rentInfo : new RentInfoVO());

        return IResponse.success(vo);
    }

    @ApiOperation(value = "根据合同号码查询渠道信息")
    @PostMapping("/channelInfo")
    public IResponse<BasicChannelInfo> channelInfo(@RequestParam("contractNo") String contractNo) {
        BasicChannelInfo basicChannelInfo = basicChannelInfoService.getOne(Wrappers.<BasicChannelInfo>lambdaQuery().
                eq(BasicChannelInfo::getContractNo, contractNo));
        return IResponse.success(basicChannelInfo);
    }

    @ApiOperation(value = "根据合同号码查询主共担基本信息（多条数据，列表格式）")
    @PostMapping("/custBaseInfoList")
    public IResponse<List<BasicCustBaseInfo>> custBaseInfoList(@RequestParam("contractNo") String contractNo) {
        List<BasicContractCustRelation> basicContractCustRelations = basicContractCustRelationService.list(Wrappers.<BasicContractCustRelation>lambdaQuery().
                eq(BasicContractCustRelation::getContractNo, contractNo));
        List<BasicCustBaseInfo> basicCustBaseInfos = new ArrayList<>();
        if (EmptyUtils.isNotEmpty(basicContractCustRelations)) {
            List<String> custNos = new ArrayList<>();
            for (BasicContractCustRelation cust : basicContractCustRelations) {
                custNos.add(cust.getCustNo());
            }
            List<BasicCustBaseInfo> list = basicCustBaseInfoService.list(Wrappers.<BasicCustBaseInfo>lambdaQuery().
                    in(BasicCustBaseInfo::getCustNo, custNos));
            if (EmptyUtils.isNotEmpty(basicCustBaseInfos)) {
                for (BasicCustBaseInfo base : list) {
                    for (BasicContractCustRelation cust : basicContractCustRelations) {
                        if (base.getCustNo().equals(cust.getCustNo())) {
                            base.setCustRole(cust.getCustRole());
                        }
                    }
                }
                basicCustBaseInfos.addAll(list);
            }
        }
        return IResponse.success(basicCustBaseInfos);
    }

    @ApiOperation(value = "根据合同号码查询主借人/共借人/担保人详细信息（custRole参数不传默认查询主借人）")
    @PostMapping("/custDetailInfo")
    public IResponse<BasicCustPersonalDetail> custDetailInfo(@RequestParam("contractNo") String contractNo,
                                                             @RequestParam(value = "custRole", defaultValue = "MAIN_PERSON") String custRole) {
        BasicContractCustRelation basicContractCustRelation = basicContractCustRelationService.getOne(Wrappers.<BasicContractCustRelation>lambdaQuery().
                eq(BasicContractCustRelation::getContractNo, contractNo)
                .eq(BasicContractCustRelation::getCustRole, custRole));
        BasicCustPersonalDetail basicCustPersonalDetail = basicCustPersonalDetailService.getOne(Wrappers.<BasicCustPersonalDetail>lambdaQuery().
                eq(BasicCustPersonalDetail::getCustNo, basicContractCustRelation.getCustNo()));
        return IResponse.success(basicCustPersonalDetail);
    }

    @ApiOperation(value = "根据合同号码查询主共担详细信息")
    @PostMapping("/custDetailInfoList")
    public IResponse<List<BasicCustPersonalDetail>> custDetailInfoList(@RequestParam("contractNo") String contractNo) {
        List<BasicContractCustRelation> basicContractCustRelations = basicContractCustRelationService.list(Wrappers.<BasicContractCustRelation>lambdaQuery().
                eq(BasicContractCustRelation::getContractNo, contractNo));
        List<BasicCustPersonalDetail> basicCustBaseInfos = new ArrayList<>();
        if (EmptyUtils.isNotEmpty(basicContractCustRelations)) {
            List<String> custNos = new ArrayList<>();
            for (BasicContractCustRelation cust : basicContractCustRelations) {
                custNos.add(cust.getCustNo());
            }
            List<BasicCustPersonalDetail> list = basicCustPersonalDetailService.list(Wrappers.<BasicCustPersonalDetail>lambdaQuery().
                    in(BasicCustPersonalDetail::getCustNo, custNos));
            if (EmptyUtils.isNotEmpty(basicCustBaseInfos)) {
                basicCustBaseInfos.addAll(list);
            }
        }
        return IResponse.success(basicCustBaseInfos);
    }

    @ApiOperation(value = "根据合同号码查询主共担联系电话信息（custRole参数不传默认查询主借人）")
    @PostMapping("/custContactInfoList")
    public IResponse<List<BasicCustContactDetails>> custContactInfoList(@RequestParam("contractNo") String contractNo,
                                                                        @RequestParam(value = "custRole", defaultValue = "MAIN_PERSON") String custRole) {
        BasicContractCustRelation basicContractCustRelation = basicContractCustRelationService.getOne(Wrappers.<BasicContractCustRelation>lambdaQuery().
                eq(BasicContractCustRelation::getContractNo, contractNo)
                .eq(BasicContractCustRelation::getCustRole, custRole));
        List<BasicCustContactDetails> basicCustContactDetails = basicCustContactDetailsService.list(Wrappers.<BasicCustContactDetails>lambdaQuery().
                eq(BasicCustContactDetails::getCustNo, basicContractCustRelation.getCustNo()));
        return IResponse.success(basicCustContactDetails);
    }

    @ApiOperation(value = "根据合同号码查询主共担地址信息（custRole参数不传默认查询主借人）")
    @PostMapping("/custAddressInfoList")
    public IResponse<List<BasicCustAddressDetails>> custAddressInfoList(@RequestParam("contractNo") String contractNo,
                                                                        @RequestParam(value = "custRole", defaultValue = "MAIN_PERSON") String custRole) {
        BasicContractCustRelation basicContractCustRelation = basicContractCustRelationService.getOne(Wrappers.<BasicContractCustRelation>lambdaQuery().
                eq(BasicContractCustRelation::getContractNo, contractNo)
                .eq(BasicContractCustRelation::getCustRole, custRole));
        List<BasicCustAddressDetails> basicCustAddressDetails = basicCustAddressDetailsService.list(Wrappers.<BasicCustAddressDetails>lambdaQuery().
                eq(BasicCustAddressDetails::getCustNo, basicContractCustRelation.getCustNo()));
        return IResponse.success(basicCustAddressDetails);
    }

    @ApiOperation(value = "根据合同号码查询紧急联系人信息")
    @PostMapping("/custContactsInfoList")
    public IResponse<List<BasicCustContacts>> custContactsInfoList(@RequestParam("contractNo") String contractNo) {
        List<BasicCustContacts> basicCustContactss = basicCustContactsService.list(Wrappers.<BasicCustContacts>lambdaQuery().
                eq(BasicCustContacts::getContractNo, contractNo));
        return IResponse.success(basicCustContactss);
    }

    @ApiOperation(value = "根据合同号码查询车辆资产信息列表数据")
    @PostMapping("/carDetailsList")
    public IResponse<List<BasicCarDetails>> carDetailsList(@RequestParam("contractNo") String contractNo) {
        List<BasicCarDetails> basicCarDetails = basicCarDetailsService.list(Wrappers.<BasicCarDetails>lambdaQuery().
                eq(BasicCarDetails::getContractNo, contractNo));
        return IResponse.success(basicCarDetails);
    }

    @ApiOperation(value = "根据合同号码查询罚息列表数据")
    @PostMapping("/findPenaltyInterest")
    public IResponse<List<BasicPenaltyInterest>> findPenaltyInterest(@RequestParam("contractNo") String contractNo) {
        List<BasicPenaltyInterest> basicPenaltyInterests = basicPenaltyInterestService.list(Wrappers.<BasicPenaltyInterest>lambdaQuery().
                eq(BasicPenaltyInterest::getContractNo, contractNo));
        return IResponse.success(basicPenaltyInterests);
    }

    @ApiOperation(value = "根据合同号码查询费用列表数据(去除罚息)")
    @PostMapping("/findExpense")
    public IResponse<List<BasicExpenseRecord>> findExpense(@RequestParam("contractNo") String contractNo) {
        List<BasicExpenseRecord> basicExpenseRecords = basicExpenseRecordService.list(Wrappers.<BasicExpenseRecord>lambdaQuery().
                eq(BasicExpenseRecord::getContractNo, contractNo).ne(BasicExpenseRecord::getCostType, FeeTypeEnum.penalty));
        BasicMainInfo basicMainInfo = basicMainInfoService.getOne(Wrappers.<BasicMainInfo>lambdaQuery()
                .eq(BasicMainInfo::getContractNo, contractNo));
        for (BasicExpenseRecord basicExpenseRecord : basicExpenseRecords) {
            basicExpenseRecord.setEndDate(basicMainInfo.getEndDate());
        }
        return IResponse.success(basicExpenseRecords);
    }


    @ApiOperation(value = "合同数据")
    @PostMapping("/deTs")
    public IResponse<List<BasicExpenseRecord>> deTs(@RequestParam("contractNo") String contractNo) {
        List<BasicExpenseRecord> basicExpenseRecords = basicExpenseRecordService.list(Wrappers.<BasicExpenseRecord>lambdaQuery().
                eq(BasicExpenseRecord::getContractNo, contractNo).ne(BasicExpenseRecord::getCostType, FeeTypeEnum.penalty));
        return IResponse.success(basicExpenseRecords);
    }


    @ApiOperation(value = "根据合同号码查询应收数据")
    @PostMapping("/financialAgree")
    public IResponse financialAgree(@RequestParam("contractNo") String contractNo) {
        ReceivableInfoVO receivableInfoVO = new ReceivableInfoVO();
        List<BasicReceiptRecord> basicReceiptRecords = basicReceiptRecordService.list(Wrappers.<BasicReceiptRecord>lambdaQuery().
                eq(BasicReceiptRecord::getContractNo, contractNo));
        List<BasicExpenseRecord> basicExpenseRecords = basicExpenseRecordService.list(Wrappers.<BasicExpenseRecord>lambdaQuery().
                eq(BasicExpenseRecord::getContractNo, contractNo));
        List<BasicRepaymentPlan> basicRepaymentPlans = basicRepaymentPlanService.list(Wrappers.<BasicRepaymentPlan>lambdaQuery().
                eq(BasicRepaymentPlan::getContractNo, contractNo));
        BigDecimal BasicRepaymentPlan = BigDecimal.ZERO;
        for (BasicExpenseRecord basicExpenseRecord : basicExpenseRecords) {
            if (basicExpenseRecord.getCostType().equals(FeeTypeEnum.penalty)) {
                receivableInfoVO.setSumPenaltyAmt(receivableInfoVO.getSumPenaltyAmt().add(basicExpenseRecord.getRemainingAmt()));
            } else {
                receivableInfoVO.setSumRemainingAmt(receivableInfoVO.getSumRemainingAmt().add(basicExpenseRecord.getRemainingAmt()));
            }
//            for (BasicRepaymentPlan basicRepaymentPlan : basicRepaymentPlans) {
//                if (basicRepaymentPlan.getStatus().equals(RepaymentStatusEnum.UNPAID) || basicRepaymentPlan.getStatus().equals(RepaymentStatusEnum.OVERDUE)) {
//                    BasicRepaymentPlan.add(basicRepaymentPlan.getReceivableRent());
//                    receivableInfoVO.setSumReceivablePrinciple(receivableInfoVO.getSumReceivablePrinciple().add(basicRepaymentPlan.getReceivablePrinciple()));
//                    receivableInfoVO.setSumReceivableInterest(receivableInfoVO.getSumReceivableInterest().add(basicRepaymentPlan.getReceivableInterest()));
//                }
//            }
//            receivableInfoVO.setOutstandingTotalAmt(BasicRepaymentPlan.add(receivableInfoVO.getSumPenaltyAmt().add(receivableInfoVO.getSumRemainingAmt())));
            for (BasicReceiptRecord basicReceiptRecord : basicReceiptRecords) {
                receivableInfoVO.setSumUnusedAmt(receivableInfoVO.getSumUnusedAmt().add(basicReceiptRecord.getUnusedAmt()));
            }

        }
        for (BasicRepaymentPlan basicRepaymentPlan : basicRepaymentPlans) {
            if (basicRepaymentPlan.getStatus().equals(RepaymentStatusEnum.UNPAID) || basicRepaymentPlan.getStatus().equals(RepaymentStatusEnum.OVERDUE)) {
                BasicRepaymentPlan.add(basicRepaymentPlan.getReceivableRent());
                receivableInfoVO.setSumReceivablePrinciple(receivableInfoVO.getSumReceivablePrinciple().add(basicRepaymentPlan.getReceivablePrinciple()));
                receivableInfoVO.setSumReceivableInterest(receivableInfoVO.getSumReceivableInterest().add(basicRepaymentPlan.getReceivableInterest()));
            }
        }
        receivableInfoVO.setOutstandingTotalAmt(BasicRepaymentPlan.add(receivableInfoVO.getSumPenaltyAmt().add(receivableInfoVO.getSumRemainingAmt()).add(receivableInfoVO.getSumReceivablePrinciple()).add( receivableInfoVO.getSumReceivableInterest())));
        return IResponse.success(receivableInfoVO);
    }

}
